﻿	using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public interface wzlzIAPInterface{
    void SuccessBuy(string productId);
    void FailBuy(string productId, string strMessage);
    void CancleBuy(string productId, string strMessage);
}


public class AndroidChannelDemoController : MonoBehaviour, wzlzIAPInterface{
	public UILabel lblRetString;
	public UILabel lblMainActivity;

	public void Start(){
//		YIjieDanjiManager.Instance().Init();
//		YIjieDanjiManager.Instance().IsMusicEnabled();
	}

	
	public void OnBtnInitClick(){
		AndroidChannelPluginManager.Instance().Init();
	}

	public void OnBtnTestClick(){
		Debug.Log("OnBtnTestClick");

		using (AndroidJavaClass jc = new AndroidJavaClass("com.tentap.testfunc.TestFunc")){
			int r = Random.Range(0, 100);
			Debug.Log("Random: " + r);
			string strRet = jc.CallStatic<string>("GetNumberStr", r);
			lblRetString.text = strRet;
 		}
	}

	public void OnBtnTestMainActivity(){
		using(AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){
			using(AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity")){
				int r = Random.Range(0, 100);
				Debug.Log("Random: " + r);
				string strRet = jo.Call<string>("GetNumberStr", r);
				lblMainActivity.text = "4399: " + strRet;
			}
		}
	}

	public void OnBtnPayClick(){
//		AndroidChannelPluginManager.Instance().Pay(1, "testProductId", "测试1元购买", CbPaySuccess, CbPayFail);
		AndroidChannelPluginManager.Instance().Pay(1, "com.tentap.wzlz.Android.GiftBox", "超值礼包", "超值礼包中将包含很多好东西", CbPaySuccess, CbPayFail, CbPayCancel);
		Debug.Log("OnBtnPayClick();");
//		YIjieDanjiManager.Instance().Pay("0", this);
	}


	public void CbPaySuccess(string productId){
		Debug.Log("CbPaySuccess(): " + productId);
	}

	public void CbPayFail(string err){
		Debug.Log("CbPayFail(): " + err);
	}

	public void CbPayCancel(string err){
		Debug.Log("CbPayCancel(): " + err);
	}

	public void OnBtnLoginClick(){
		AndroidChannelPluginManager.Instance().Login(CbLoginSuccess, CbLoginFail);

	}

	public void CbLoginSuccess(WuZiLianZhu.UserInfo user){
		Debug.Log("CbLoginSuccess(): " + user.BindingId + "-" + user.Name);
	}

	public void CbLoginCancel(string ret){
		Debug.Log("CbLoginCancel(): " + ret);

	}

	public void CbLoginFail(string ret){
		Debug.Log("CbLoginFail(): " + ret);

	}

	public void OnBtnLogoutClick(){
		AndroidChannelPluginManager.Instance().Logout(CbLogoutDone);
	}

	public void CbLogoutDone(string msg){
		Debug.Log("CbLogoutDone(): " + msg);

	}

	public void SuccessBuy(string productId){
		Debug.Log("SuccessBuy(): " + productId);
	}

    public void FailBuy(string productId, string strMessage){
		Debug.Log("FailBuy(): " + productId + " err:" + strMessage);
	}
    
	public void CancleBuy(string productId, string strMessage){
		Debug.Log("CancleBuy(): " + productId + " err:" + strMessage);
	}

	#region Check Pay
	public void OnBtnCheckPay(){
		AndroidChannelPluginManager.Instance().CheckPay(CbDelivery, CbNothing);
	}

	public void CbDelivery(string productId){
		Debug.Log("CbDelivery(): " + productId);

	}

	public void CbNothing(){
		Debug.Log("CbNothing(): ");
	}
	#endregion

	void Update () {
       
        //退出键
        if (Application.platform == RuntimePlatform.Android && (Input.GetKeyDown(KeyCode.Escape)))
        {
    		AndroidChannelPluginManager.Instance().Exit();
        }
    }
}
